@{ ViewData["Title"]="管理员信息";
var m = ViewBag.Data;
}
<div class="card mt-2 mb-2"
     style="min-height:400px;">
  <div class="card-header d-flex justify-content-between">
    <span>管理员信息</span>
  </div>
  <div class="card-body">
    <div class="row">
      <div class="col-6 offset-3">
        <form id="formInfo"
              enctype="multipart/form-data">
          <input type="hidden"
                 id="managerid"
                 value="@m?.ManagerID" />
          <div class="mb-3 row">
            <label for="mname"
                   class="col-sm-2 col-form-label">姓名</label>
            <div class="col-sm-9">
              <input type="text"
                     class="form-control"
                     id="mname"
                     value="@m?.Name">
            </div>
          </div>
          <div class="mb-3 row">
            <label for="mphone"
                   class="col-sm-2 col-form-label">电话</label>
            <div class="col-sm-9">
              <input type="text"
                     class="form-control"
                     id="mphone"
                     value="@m?.Phone">
            </div>
          </div>
          <div class="mb-3 row">
            <label for="sex"
                   class="col-sm-2 col-form-label">性别</label>
            <div class="col-sm-9">
              <input type="text"
                     class="form-control"
                     id="sex"
                     value="@m?.Sex">
            </div>
          </div>
          <div class="mb-3 row">
            <label for="password"
                   class="col-sm-2 col-form-label">密码</label>
            <div class="col-sm-9">
              <textarea rows="3"
                        class="form-control"
                        id="password">@m?.Password</textarea>
            </div>
          </div>
          <div class="mb-3 row">
            <div class="col-12 text-center">
              <button type="button"
                      id="btn-submit"
                      class="btn btn-primary mb-3">提交</button>&nbsp;
              <button type="reset"
                      class="btn btn-light mb-3">重置</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

@section DemoScripts{
<script>
  $(function () {
    //激活菜单项
    $("#menu_managers").addClass("active");
    //提交处理
    $("#btn-submit").on("click", function () {
      //按照表单本身的设置上传
      let formData = new FormData($("#formInfo")[0]);
      formData.append("managerid", $("#managerid").val());
      formData.append("mname", $("#mname").val());
      formData.append("mphone", $("#mphone").val());
      formData.append("sex", $("#sex").val());
      formData.append("password", $("#password").val());
      $.ajax({
        type: $("#managerid").val() ? "post" : "put",
        url: "/admin/managers/info",
        data: formData,
        dataType: "json",
        contentType: false,
        processData: false,
        success: function (response) {
          alert(response.message);
          if (response.status == 0) location.href = "/admin/managers"
        }
      });
    })
  });
</script>
}
